TRUNCATE
Section: System Calls (2)
Index
Return to Main Contents
BSD mandoc
BSD 4.2
NAME
truncate
ftruncate
- truncate a file to a specified length
SYNOPSIS
Fd #include <unistd.h>
Ft int
Fn truncate const char *path off_t length
Ft int
Fn ftruncate int fd off_t length
DESCRIPTION
Fn Truncate
causes the file named by
Fa path
or referenced by
Fa fd
to be truncated to at most
Fa length
bytes in size. If the file previously
was larger than this size, the extra data
is lost.
With
Fn ftruncate ,
the file must be open for writing.
RETURN VALUES
A value of 0 is returned if the call succeeds. If the call
fails a -1 is returned, and the global variable
errno
specifies the error.
ERRORS
Fn Truncate
succeeds unless:
- Bq Er ENOTDIR
-
A component of the path prefix is not a directory.
- Bq Er ENAMETOOLONG
-
A component of a pathname exceeded
{NAME_MAX}
characters, or an entire path name exceeded
{PATH_MAX}
characters.
- Bq Er ENOENT
-
The named file does not exist.
- Bq Er EACCES
-
Search permission is denied for a component of the path prefix.
- Bq Er EACCES
-
The named file is not writable by the user.
- Bq Er ELOOP
-
Too many symbolic links were encountered in translating the pathname.
- Bq Er EISDIR
-
The named file is a directory.
- Bq Er EROFS
-
The named file resides on a read-only file system.
- Bq Er ETXTBSY
-
The file is a pure procedure (shared text) file that is being executed.
- Bq Er EIO
-
An I/O error occurred updating the inode.
- Bq Er EFAULT
-
Fa Path
points outside the process's allocated address space.
Fn Ftruncate
succeeds unless:
- Bq Er EBADF
-
The
Fa fd
is not a valid descriptor.
- Bq Er EINVAL
-
The
Fa fd
references a socket, not a file.
- Bq Er EINVAL
-
The
Fa fd
is not open for writing.
SEE ALSO
open(2)
BUGS
These calls should be generalized to allow ranges
of bytes in a file to be discarded.
HISTORY
The
Fn truncate
and
Fn ftruncate
function calls appeared in
BSD 4.2
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUES
-
- ERRORS
-
- SEE ALSO
-
- BUGS
-
- HISTORY
-
This document was created by
man2html,
using the manual pages.
Time: 19:41:54 GMT, December 25, 2022